package edu.neusoft.yuejian_09.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import edu.neusoft.yuejian_09.R;
import edu.neusoft.yuejian_09.adapter.ClubTrainAdapter;
import edu.neusoft.yuejian_09.bean.Train;
import edu.neusoft.yuejian_09.model.ClubModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ClubTrainActivity extends AppCompatActivity {
        private RecyclerView recyclerView;
        private TextView t_name;
        private ImageView btn_left;
        private int train_id;
        private String train_name;
        private String train_pic;
        private Intent intent;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_club_train);
                initViews();
                initEvents();
                initData();
        }


        public void initViews() {
                btn_left = (ImageView) findViewById(R.id.btn_left);
                recyclerView = (RecyclerView) findViewById(R.id.club_train);
                t_name = (TextView) findViewById(R.id.t_name);

        }

        //基本事件
        public void initEvents() {
                btn_left.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                                finish();
                        }
                });
                recyclerView.setItemAnimator(new DefaultItemAnimator());
                recyclerView.setLayoutManager(new LinearLayoutManager(this));
        }


        //获取数据
        public void initData() {

                getClubtrains();
        }


        private void getClubtrains() {
                Bundle bundle = this.getIntent().getExtras();
                String c_id = bundle.getString("club_id");
                Log.d("userbg", "club_id");
                System.out.print(c_id);
                ClubModel clubModel = new ClubModel();//diaoyong
                Call call = clubModel.getClubtrains(c_id);
                call.enqueue(new Callback<List<Train>>() {
                        @Override
                        public void onResponse(Call<List<Train>> call, Response<List<Train>> response) {
                                List<Train> activity = response.body();
                                // mDataList = (List) response.body();
                                recyclerView.setAdapter(new ClubTrainAdapter(ClubTrainActivity.this, activity));
                        }

                        @Override
                        public void onFailure(Call<List<Train>> call, Throwable t) {
                                Toast.makeText(ClubTrainActivity.this, "fail", Toast.LENGTH_SHORT).show();
                        }
                });

        }
}
